package com.tbit.uqbike.serialize;

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.tbit.uqbike.enums.TagBindStatus;

import java.lang.reflect.Type;

/**
 * TagBindStatus 反序列化
 *
 *
 * @author <a href="mailto:chen.chaoxiong@tbit.com.cn">ChenChaoXiong</a>
 * @since 2024/7/10
 */
public class TagBindStatusDeserializer implements ObjectDeserializer {
    @Override
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        String value = parser.parseObject(String.class);
        TagBindStatus status = TagBindStatus.getTagBindStatsByCode(value);
        if (status == null) {
            throw new IllegalArgumentException("Invalid TagBindStatus code: " + status);
        }
        return (T) status;

    }

    @Override
    public int getFastMatchToken() {
        return JSONToken.LITERAL_STRING;
    }
}
